<template>
  <el-dialog title="充值/扣除云豆" :visible.sync="visible" :close-on-click-modal="false" width="400px">
    <div class="disFlxCC">
      <el-input-number v-model="params.number" :step="2" :precision="2" :min="1" placeholder="请输入需要充值/扣除的云豆数量" controls-position="right" style="width:80%;"></el-input-number>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="danger" @click="confirm(0)">立即扣除</el-button>
      <el-button type="primary" @click="confirm(1)">确认充值</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { userRecharge } from "@/api/user/user";
export default {
  data() {
    return {
      visible: false,
      params: {
        uid: undefined, // 充值用户ID - 二选一
        expId: undefined, // 充值专家ID - 二选一
        pm: 1, // 0扣费   1充值
        number: undefined,
      }
    };
  },
  methods: {
    show(obj) {
      if(this.$store.state.user.userInfo.userId === 1){
        Object.assign(this.params, obj);
        this.visible = true;
      }
    },
    confirm(pm) {
      this.params.pm = pm;
      userRecharge(this.params).then(()=>{
        this.$message.success(pm === 1 ? '充值成功' : '成功扣除');
        this.visible = false;
        this.$emit('refresh');
      });
    }
  },
};
</script>

<style lang="scss" scoped></style>
